package com.stqf.scala;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.RandomUtil;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Stream;

/**
 * Created By admin
 * <br/>Date: 2025/5/8 15:54
 * <br/>Description:
 */
public class ScalaApplication {

    private static final Logger log = LoggerFactory.getLogger(ScalaApplication.class);

    private static final ExecutorService worker = Executors.newFixedThreadPool(
            8,
            new ThreadFactoryBuilder().setNameFormat("worker-%03d").build()
    );

    public static void main(String[] args) {
        long finishTs = Stream.of(args).filter(it -> DatePattern.REGEX_NORM.matcher(it).find()).findFirst()
                .map(it -> LocalDateTimeUtil.parse(it, DatePattern.NORM_DATETIME_FORMATTER))
                .orElseGet(() -> LocalDateTime.now().plusMinutes(8))
                .atZone(ZoneId.systemDefault())
                .toInstant()
                .toEpochMilli();

        log.info("进程启动参数为 ... {}", Arrays.toString(args));

        for (int i = 0; i < 8; i++) {
            worker.submit(() -> {
                while (System.currentTimeMillis() < finishTs) {
                    log.info("些些疏懒亦何方 ... {} ", RandomUtil.randomBoolean());
                    log.warn("些些疏懒亦何方 ... {} ", RandomUtil.randomBoolean());

                    log.trace("些些疏懒亦何方 ... {} ", RandomUtil.randomBoolean());
                    log.debug("些些疏懒亦何方 ... {} ", RandomUtil.randomBoolean());
                    log.error("些些疏懒亦何方 ... {} ", RandomUtil.randomBoolean());
                }
            });
        }

    }

}
